package com.netcracker.studportal.server.util;

import java.io.File;
import java.util.Locale;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.netcracker.studportal.server.model.Exam;
import com.netcracker.studportal.server.model.ExamWithResult;
import com.netcracker.studportal.server.model.Faculty;
import com.netcracker.studportal.server.model.Material;
import com.netcracker.studportal.server.model.Professor;
import com.netcracker.studportal.server.model.Student;
import com.netcracker.studportal.server.model.Subject;
import com.netcracker.studportal.server.model.University;
import com.netcracker.studportal.server.model.User;

@SuppressWarnings("deprecation")
public class HibernateUtil {
	
	private static  SessionFactory sessionFactory;

	static {
		// This line is needed for right working
		Locale.setDefault(Locale.ENGLISH);
		try {
			File config = new File("config/hibernate.cfg.xml");
			System.out.println("Hibernate Config = " + config.getAbsolutePath());
			sessionFactory=new Configuration()
			.addAnnotatedClass(Student.class)
			.addAnnotatedClass(University.class)
			.addAnnotatedClass(Faculty.class)
			.addAnnotatedClass(Professor.class)
			.addAnnotatedClass(User.class)
			.addAnnotatedClass(Subject.class)
			.addAnnotatedClass(Exam.class)
			.addAnnotatedClass(ExamWithResult.class)
			.addAnnotatedClass(Material.class)
			.configure(config).buildSessionFactory();
			
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}
